package exam;

/**
 * @Author 刘牌
 * @Date 2020/2/7 0007 16:14
 * @Version 1.0
 */

public class A {
    private static A a=null;
    String name; private A() {

    }
    public String toString() {
        return
                "["+this.getClass().getName()+":name="+this.name+"]";
    }
    public static A getInstance() {
        if(a==null) {
            a=new A();
        }
        return a;
    }
    public void setName(String name) {
        this.name=name;
    }

    public static void main(String[] args) {
        A a1=A.getInstance();
        a1.setName("B");
        A a2=A.getInstance();
        a1.setName("C");
        System.out.println(a2);
    }
}
